package cn.kevinproject.dingtalk_robot.schedule;

import cn.kevinproject.dingtalk_robot.client.Producer;
import cn.kevinproject.dingtalk_robot.client.ProducerFactory;
import cn.kevinproject.dingtalk_robot.datacenter.DataGrabRegistrar;
import cn.kevinproject.dingtalk_robot.msg.MultiActionCardMessage;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import lombok.val;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * @author kevin lau
 */
@Slf4j
@Component
@RequiredArgsConstructor
public class ScheduleStarter {

    private final ProducerFactory producerFactory;

    private final DataGrabRegistrar dataGrabRegistrar;


    @Scheduled(cron = "0 30 9 * * ?")
    public void today() {
        dataGrabRegistrar.clearCache();
        val action = new MultiActionCardMessage();
        action.setBtnOrientation("1");
        action.setTitle("新鲜事，简单报");
        List<MultiActionCardMessage.Button> buttons = new ArrayList<>();
        val btn = new MultiActionCardMessage.Button();
        btn.setTitle("✨微博热搜✨");
        btn.setActionUrl("http://robot.kevinproject.cn/data/grab?key=weibo&robot=jiesuan");
        buttons.add(btn);
        val btn2 = new MultiActionCardMessage.Button();
        btn2.setTitle("✨知乎热搜✨");
        btn2.setActionUrl("http://robot.kevinproject.cn/data/grab?key=zhihu&robot=jiesuan");
        buttons.add(btn2);
        action.setBtns(buttons);
        action.setText("![screenshot](https://image.kevinproject.cn/uPic/猫可爱.png)\n" +
                " ### 新鲜事简单报 王尼玛带你看日报\n "+
                "> 宇宙还挺谦虚的，明明拥有一切，却叫自己太空。");
        Producer producer = producerFactory.buildProducer("Java");
        producer.sendMsg(action);
        log.info("热搜发送成功");
    }
}
